import { createRouter, createWebHistory } from "vue-router";
import NProgress from "nprogress";
import "nprogress/nprogress.css";

const router = createRouter({
  history: createWebHistory(),
  routes: [
    { path: "/", redirect: "/login" },
    {
      path: "/login",
      component: () => import("@/views/login/Login.vue"),
    },
    {
      path: "/mian",
      component: () => import("@/views/main/Main.vue"),
      redirect: "/home",
      children: [
        {
          path: "/home",
          component: () => import("@/views/home/Home.vue"),
        },
        {
          path: "/users",
          component: () => import("@/views/users/Users.vue"),
        },
        {
          path: "/network",
          component: () => import("@/views/network/Network.vue")
        }
      ],
    },
  ],
});

// router.beforeEach((to, from, next) => {
//   NProgress.start();
//   if (to.path === "/login") {
//     next();
//   } else if (sessionStorage.getItem("userName") == null && sessionStorage.getItem("roleId") == null) {
//     next("/login");
//   } else if (to.matched.length === 0) {
//     from.path ? next({ path: from.path }) : next("/");
//   } else {
//     next();
//   }
// });

router.afterEach(() => {
  NProgress.done();
});

export default router;
